package com.ui.swing;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.tidemark.Stock;
import com.tidemark.StockDataModel;

public class SwingDataModel extends AbstractTableModel implements StockDataModel{

	private static String[] columns = new String[] {"Code", "Name", "Comment"};	
	private Vector<Stock> data;
	
	public SwingDataModel() {
		data = new Vector<Stock>();
	}
	
	@Override
	public void addStock(Stock stock) {
		data.add(stock);
		fireTableDataChanged();
	}
	
	@Override
	public void removeAllStocks(){
		data.removeAllElements();
		fireTableDataChanged();
	}

	@Override
	public void addSeparator() {
		// TODO Auto-generated method stub
		
	}
	
	public int getColumnCount() { 
		return columns.length; 
	}
    
	public int getRowCount() { 
		return data.size();
	}
    
	public Object getValueAt(int row, int col) {
		Stock item = data.get(row);
		switch(col) {
		case 0:
			return item.getCode();
		case 1:
			return item.getName();
		case 2:
			return item.getComments();
			default:
				return "";
		}
    }
    public String getColumnName(int column) {
    	return columns[column];
    }
    public Class getColumnClass(int c) {
    	return getValueAt(0, c).getClass();
    }
    
    public boolean isCellEditable(int row, int col) {
    	return false;
    }
    
    public void setValueAt(Object aValue, int row, int column) { 
    	//Not support edit 
    } 
}
